define(function(require, exports){
	exports.onMain = function(boot,data,app){
		var user = app.getUserCurrent();
		//if (user.Type == 2){
		//	// 如果是直客，跳转到admin/log
		//	app.controller.navigate('admin/log');
		//	return false;
		//}

		if (!app.routerValid('user.list')) {
			return;
		}
		var title = LANG('子账号管理');
		var con = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title:title,
			type: 'sidebar'
		});

		con.createBusiness(data.name  + '_bar', 'layout/navbar.base', {
			'contentType': 'info',
			'autoBuild': true,
			'data': data,
			'addTitle': title,
			'type': 'admin'
		}, function(mod, created){
			if(mod){
				mod.setData(data, title);
			}
		});

		con.createBusiness(data.name, 'admin/customer/action/list.main', {
			tabText: title
		}, function(mod, created){
			if(created){
				mod.reload();
			}
		});
	};

	exports.onEdit = function(boot, data, app){
		var id = data.param;
		var auth = id ? 'user.info' : 'user.add';
		if (!app.routerValid(auth)) {
			return;
		}

		// 不是添加产品账号的iframe里面，则不可以进去没有用户id的编辑页面
		if (window.top == window && !id)
		{
			app.controller.navigate('admin/customer');
			return;
		}
		var title = LANG('编辑子账号');
		var cont = app.getContainer({
			scenes: 'main',
			full: false,
			sitelist: false,
			setup_btn: false,
			title:title,
			type: 'scroll'
		});

		cont.createBusiness(data.name  + '_bar', 'layout/navbar.base', {
			'contentType': 'info',
			'autoBuild': true,
			'data': data,
			'addTitle': title,
			'type': ''
		}, function(mod, created){
			if(mod){
				mod.setData(data, title);
			}
		});

		var id = data.param;
		var mod = app.core.get(data.name);
		if (!mod){
			app.core.createAsync(data.name, 'addAccount/action/add.base', {
				'el': cont.getDOM()
			},function(mod){
				mod.reset();
				if(id){
					mod.setTitle(title).load(id);
				}
			});
		}
		else {
			mod.reset().setTitle(title).load(id);
		}
	};

});
